//
//  ProductListCell.m
//  Finance
//
//  Created by cheng xiang on 13-6-10.
//  Copyright (c) 2013年 cheng xiang. All rights reserved.
//

#import "UserBuyCell.h"

@implementation UserBuyCell
@synthesize bankView = _bankView,subjectLabel = _subjectLabel,targetLabel=_targetLabel,timeLabel = _timeLabel,cellbgView = _cellbgView;
//@synthesize fareLabel = _fareLabel, typeidLabel = _typeidLabel, faceValueLabel = _faceValueLabel,ideaLabel = _ideaLabel;
@synthesize startMoneyLabel = _startMoneyLabel, currencyLabel = _currencyLabel;
@synthesize bankNameLabel = _bankNameLabel, titleLabel = _titleLabel,starView = _starView,benfitLabel = _benfitLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        _bankView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 10, 40, 40)];
                
        _bankNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 52, 90, 20)];
        [_bankNameLabel setBackgroundColor:[UIColor clearColor]];
        [_bankNameLabel setTextAlignment:NSTextAlignmentCenter];
        _bankNameLabel.font = [UIFont boldSystemFontOfSize:14];
        
        _subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 15, 230, 20)];
        [_subjectLabel setBackgroundColor:[UIColor clearColor]];
        _subjectLabel.font = [UIFont boldSystemFontOfSize:18];
        //        _subjectLabel.lineBreakMode = NSLineBreakByWordWrapping;
        //        _subjectLabel.numberOfLines = 0;
        //[_subjectLabel setFont:[UIFont systemFontOfSize:14]];
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(95, 80, 35, 20)];
        contentLabel.text = @"起售:";
        [contentLabel setBackgroundColor:[UIColor clearColor]];
        [contentLabel setFont:[UIFont boldSystemFontOfSize:14]];
        [self.contentView addSubview:contentLabel];
        
        _startMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(127, 80, 37, 20)];
        [_startMoneyLabel setBackgroundColor:[UIColor clearColor]];
        [_startMoneyLabel setTextAlignment:NSTextAlignmentCenter];
        [_startMoneyLabel setFont:[UIFont systemFontOfSize:14]];
        [_startMoneyLabel setTextColor:[UIColor grayColor]];
        
        //        _currencyLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 55, 70, 20)];
        //        [_currencyLabel setBackgroundColor:[UIColor clearColor]];
        _starView = [[UIImageView alloc] initWithFrame:CGRectMake(90, 45, 17, 17)];
        [_starView setImage:[UIImage imageNamed:@"star.png"]];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 45, 70, 20)];
        [_titleLabel setBackgroundColor:[UIColor clearColor]];
        [_titleLabel setFont:[UIFont systemFontOfSize:14]];
        
        contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(175, 45, 70, 20)];
        contentLabel.text = @"托管期限:";
        [contentLabel setBackgroundColor:[UIColor clearColor]];
        [contentLabel setFont:[UIFont boldSystemFontOfSize:15]];
        [self.contentView addSubview:contentLabel];
        
        _targetLabel = [[UILabel alloc] initWithFrame:CGRectMake(245, 45, 40, 20)];
        [_targetLabel setBackgroundColor:[UIColor clearColor]];
        [_targetLabel setTextAlignment:NSTextAlignmentCenter];
        [_targetLabel setFont:[UIFont systemFontOfSize:15]];
        [_targetLabel setTextColor:[UIColor colorWithRed:0.8 green:0.1 blue:0.1 alpha:1]];
        
        contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(285, 45, 15, 20)];
        contentLabel.text = @"天";
        [contentLabel setBackgroundColor:[UIColor clearColor]];
        [contentLabel setFont:[UIFont systemFontOfSize:15]];
        [self.contentView addSubview:contentLabel];
        
        contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 80, 65, 20)];
        contentLabel.text = @"销售截止:";
        [contentLabel setBackgroundColor:[UIColor clearColor]];
        [contentLabel setFont:[UIFont boldSystemFontOfSize:15]];
        [self.contentView addSubview:contentLabel];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(235, 80, 90, 20)];
        [_timeLabel setBackgroundColor:[UIColor clearColor]];
        [_timeLabel setFont:[UIFont systemFontOfSize:15]];
        [_timeLabel setTextColor:[UIColor grayColor]];
        
        //        _ideaLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 130, 280, 160)];
        //        [_ideaLabel setBackgroundColor:[UIColor clearColor]];
        //        _ideaLabel.lineBreakMode = NSLineBreakByWordWrapping;
        //        _ideaLabel.numberOfLines = 0;
        //        [_ideaLabel setFont:[UIFont systemFontOfSize:16]];
        //        [_ideaLabel setTextColor:[UIColor grayColor]];
        //        UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, _ideaLabel.bounds.size.width+10, _ideaLabel.bounds.size.height)];
        //        bgView.image = [textbgImage resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
        //        _ideaLabel.clipsToBounds = NO;
        //        [_ideaLabel addSubview:bgView];
        //        _faceValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 250, 140, 20)];
        //        [_faceValueLabel setBackgroundColor:[UIColor clearColor]];
        //        _fareLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 250, 150, 20)];
        //        [_fareLabel setBackgroundColor:[UIColor clearColor]];
        //        _typeidLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 275, 300, 20)];
        //        [_typeidLabel setBackgroundColor:[UIColor clearColor]];
        
        [self.contentView addSubview:_bankView];
        [self.contentView addSubview:_subjectLabel];
        [self.contentView addSubview:_startMoneyLabel];
        [self.contentView addSubview:_targetLabel];
        [self.contentView addSubview:_timeLabel];
        //        [self.contentView addSubview:_currencyLabel];
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_bankNameLabel];
        [self.contentView addSubview:_starView];
        //        [self.contentView addSubview:_ideaLabel];
        //        [self.contentView addSubview:_faceValueLabel];
        //        [self.contentView addSubview:_fareLabel];
        //        [self.contentView addSubview:_typeidLabel];
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)drawBankImage:(NSObject *)obj
{
    if ([obj isKindOfClass:[NSString class]]) {
        NSString *imageurl = (NSString *)obj;
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageurl]]];//后面使用这个url的方法
        //UIImage *image = [UIImage imageWithContentsOfFile:imageurl];
        [_bankView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
    }
}

- (void)drawCell:(NSDictionary *)dic
{
    _cellbgView.frame = CGRectMake(5, 5, self.contentView.bounds.size.width-10, 120);
    [NSThread detachNewThreadSelector:@selector(drawBankImage:) toTarget:self withObject:[dic objectForKey:@"imageUrl"]];
    
    //[dic objectForKey:@"imageUrl"]到时候用这个替换
    _startMoneyLabel.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"startMoney"]];
    _subjectLabel.text = [dic objectForKey:@"title"];
    _targetLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"mgrPeriod"]];
    //    _currencyLabel.text = [NSString stringWithFormat:@"币种:%@",[dic objectForKey:@"currency"]];
    NSString *endTime = [dic objectForKey:@"endTime"];
    NSArray *timeArray = [endTime componentsSeparatedByString:@" "];
    NSString *date = timeArray.count > 0 ? [timeArray objectAtIndex:0] : @"";
    _timeLabel.text = [NSString stringWithFormat:@"%@",date];
    NSString *typeId = [dic objectForKey:@"typeId"];
    
    if ([typeId isEqualToString:@"3"]) {
        _titleLabel.text = @"非保本";
    }else if([typeId isEqualToString:@"5"]){
        _titleLabel.text = @"保本";
    }else{
        _titleLabel.text = @"";
    }
    _bankNameLabel.text = [dic objectForKey:@"bankName"];
    _benfitLabel.text = [NSString stringWithFormat:@"%@%%",[dic objectForKey:@"expectedYield"]];
    //    _ideaLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"idea"]];
    //    _faceValueLabel.text = [NSString stringWithFormat:@"面值:%@",[dic objectForKey:@"faceValue"]];
    //    _fareLabel.text = [NSString stringWithFormat:@"费用:%@",[dic objectForKey:@"fare"]];
    //    _typeidLabel.text = [NSString stringWithFormat:@"产品类型编号:%@",[dic objectForKey:@"expectedYield"]];
}

@end
